PG = require('fckoa/db/pg')

id_by_xxx = (column)->
    (key)->
        if not key
            return
        key_id = await PG.val_id('auth.'+column, key)

        return await PG.select_val_id(
            "auth.user_"+column
            key_id
        )


module.exports = {
    password:(user_id, password, trx=PG)->
        await trx.set(
            'auth.password'
            user_id
            await require("fckoa/util/bcrypt")(password)
        )

    id_by_mail:id_by_xxx("mail")
    id_by_phone:id_by_xxx("phone")
}
